<template>
	<view>
		<view class="formsub" style="width: 80%;margin-top: 100upx;">
			<u-form :model="form" ref="uForm" >
				<u-form-item label="原卡号" :label-width='120' prop="name">
					<u-input disabled v-model="form.name" />
				</u-form-item>
				<u-form-item :label-width='120' label="新卡号" prop="intro">
					<u-input v-model="form.intro" />
				</u-form-item>
			</u-form>
			<u-button type="success" @click="submit">提交</u-button>
		</view>
	</view>
</template>

<script>
	import http from '../../common/vmeitime-http/index.js';
	export default {
		data() {
			return {
				form: {
					name: '',
					intro: '',
				},
				rules: {
					name: [{
						required: true,
						message: '请输入姓名',
						// 可以单个或者同时写两个触发验证方式 
						trigger: ['change', 'blur'],
					}],
					intro: [{
						min: 1,
						message: '卡号长度至少为1',
						trigger: ['change', 'blur']
					}]
				}
			}
		},
		methods: {
			submit(){
				let parma = {
					Card: this.form.intro
				};
				http.setCardNumber(parma)
					.then(res => {
						console.error(res.data.Data);
						if(res.data.result==1){
							uni.showToast({
								title: res.data.Message,
							  icon: 'none',
							  duration: 2e3
							})
							this.$Fpublic.cardId = this.form.intro;
							uni.setStorageSync('Cardid', this.form.intro);
						}else{
							uni.showToast({
								title: res.data.Message,
							  icon: 'none',
							  duration: 2e3
							})
						}
					})
					.catch(err => {
						console.error(err);
					});
			}
		},
		created() {
			console.log(http)
		},
		// 必须要在onReady生命周期，因为onLoad生命周期组件可能尚未创建完毕
		onReady() {
			this.form.name = uni.getStorageSync('Cardid');
			this.$refs.uForm.setRules(this.rules);
		}
	}
</script>

<style lang="scss" scoped>
	.formsub{
		margin-left: 10%;
	}
</style>
